{include file="header/index" /}
<div class="newContentBox">
    <form action="" class="layui-form">
        <div class="newForm flex_between">
            <div>
                <div class="newGroup">
                    <div class="newLabel inputText">标题</div>
                    <div class="newGroupInput">
                        <input type="text" id="key" name='key' placeholder="请输入合同标题" value="" class="layui-input cover_layui_i">
                        <input type="hidden" id="user_id" name='user_id' value="{$user_id}" class="layui-input cover_layui_i">
                    </div>
                </div>
                <div class="newGroup newBtnBox">
                    <button type="button" id="search" onclick="searchs()" class="newBtnDefault newBtnPrimary">搜索</button>
                    <button type="button" id="reset" onclick="resetSearch()" class="newBtnDefault">重置</button>
                </div>
            </div>
            <div>
                <div class="newGroup newBtnBox">
                    <button type="button" class="newBtnDefault newBtnGray" onclick="returnBack(this)"> <i class="fa fa-mail-reply"></i>返回</button>
                </div>
            </div>
        </div>
    </form>
    <!-- 分割部分 -->
    <div class="newDivision"></div>
    <div class="newListPart">
        <div class="">
            <span class="layui-inline newListTitle">纸质合同列表</span>
            <div class="layui-inline newTitleBtnBox">
               <!-- <button type="button" class="newBtnDefault newBtnPrimary" onclick="addListFun()">
                    &nbsp;&nbsp;更新管理
                </button>-->
                <!--
                <button type="button" class="newBtnDefault newBtnGray" onclick="refresh()"><i class="fa fa-undo"></i>刷新</button>-->
            </div>
        </div>
        <div class="newTableBox collapse_newbox">
            <!-- 手风琴盒子 -->
            <div class="layui-collapse" lay-accordion="" id="collapse_id"></div>
        </div>
        <!--<div id="list-content" class="collapse_newbox"></div>-->
        <div class="pageBox">
            <span onclick="del()"><!--批量删除--></span>
            <div class="newPage" id="page"></div>
        </div>
    </div>
</div>
<!-- <script type="text/javascript" src="__JS__/layui/changelayui-v2.5.6/layui/layui.all.js" charset="utf-8"></script> -->
<script>
    //**********************  layui **************************
    var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        laytpl = layui.laytpl,
        table = layui.table;
    //************************ layui end *************************
    // *********************** 页面初始化*************************
    //请求数据
    var listData = [];//列表数据
    var $nowPage = 1;
    Ajaxpage(1);
    // ***********************页面初始化**************************
    //************************** 处理函数  *****************************

    //刷新
    function refresh() {
        $('#collapse_id').html("");
        Ajaxpage($nowPage);
    }

    //搜索表单
    $("#search").click(function () {
        Ajaxpage(1);
    });

    Ajaxpage();
    function Ajaxpage(curr){
        var loadingFlag= layer.msg('正在读取数据，请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:60000 });
        $("#curr_").val(curr);
        var keyword = $('#keyword').val();
        var user_id = $('#user_id').val();
        var request_data = {};
        request_data.keyword = keyword;
        request_data.user_id = user_id;
        request_data.page = curr || 1;
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Dealer/getDealerContract", request_data, function(data){
            layer.close(loadingFlag);
            var page = data.data.page;
            $("#total_number").text(page.total);
            var getData = data.data.data.contract_enclosure;
            if(data==''){
                // 替换总的数据
                $("#collapse_id").html(
                    '<div class="layui-colla-item"><h2 class="layui-colla-title">暂无数据</h2></div>'
                );
            }else{
                console.log('getData',getData);
                var html ='';
                for(var i = 0; i < getData.length; i++){
                    html += '<div class="layui-colla-item">';
                    html += '<h2 class="layui-colla-title"><span class="ver_author">----'+getData[i].time+'</span></h2>';
                    html += i==0?'<div class="layui-colla-content layui-show">':'<div class="layui-colla-content ">';
                    var content=getData[i].content;
                    if(content !=''){
                        for(var j = 0; j < content.length; j++){
                            html += '<p style="border-bottom: 1px solid #999999;height:40px;">'+content[j].old_name+'<span style="float:right"><a class="newBtnDefault" target="_blank" href="{$local_url}'+content[j].new_name+'">查看合同原件</a></span></p>';
                        }
                    }
                    html += '</div>';
                    html += '</div>';
                }
                $("#collapse_id").html(html);

                element.init();//必须要重新渲染一次
            }
            //分页
            laypage.render({
                elem: 'AjaxPage' //分页容器的id
                ,count: page.total //总条数
                ,limit: page.row //每页条数
                ,skin: '#1AB5B7' //自定义选中色值
                ,curr: curr || 1
                ,layout: ['prev', 'page', 'next', 'skip']
                //,skip: true //开启跳页
                ,jump: function(obj, first){
                    if(!first){
                        Ajaxpage(obj.curr)
                    }
                    $('#allpage').html('第'+ obj.curr +'页，共'+ page.total_page +'页');
                }
            });
        });
    }


</script>